$(function(){
    window.uploadCallback = function(status,msg,data){
	switch(status){
	    case 'XT001':
		if(msg!=''){
		    Z.tip(msg,2);
		}
		window.location.reload();
		break;
	    case 'XT002':
		Z.alert(msg||'操作失败');
		break;
	    case 'XT003':
		Z.alert('您不具备此操作权限');
		break;
	    case 'XT004':
		Z.alert('请先登录');
		break;
	    default:
		Z.alert('未知错误!');
                  
	};
    };
	
    $('a.replace').click(function(){
	var imageName = $(this).find('img').attr('src').replace(/^.*\/([^\/]*)/,'$1');
	Z.alert({
	    content : $('#replace-form-template').tmpl({
		image_name : imageName
	    })
	});
    });
	
    $('a.edit').click(function(){
	var id = Z.parseInt($(this).attr('data'));
	Z.form({
            width: 500,
	    content: $('#form-template').tmpl({
		id: id,
		zh: $(this).parent().next().next().html().replace(/<br>/g,'\n'),
		en: $(this).parent().next().next().next().html().replace(/<br>/g,'\n')
	    }),
	    success: function(){
		window.location.reload();
	    },
	    onOpen : function(){
		Z.tab($('form .tab-button a'), $('form .tab-content'), ['active','']);
	    }
	});
    });
    
    $('ul.menu>li').each(function(){
	Z.tab($(this).find('.tab-button a'), $(this).find('.tab-content'), ['active','']);
    });

    Z.tab($('h3.contact').next().find('a'), [$('h3.contact').next().next()[0],$('h3.contact').next().next().next()[0]], ['active','']);
    
    Z.tab($('ul.tab-button.top-news a'), $('.tab-content.top-news'), ['active','']);
    
    $('a.top-company-news').click(function(){
        Z.ajax({
            type: 'post',
            url : Z.url('/backend/setting/update_by_key',true),
            data: {key: 'home_top_news_type',value : 1}
        });
    });
    
    $('a.top-industry-news').click(function(){
        Z.ajax({
            type: 'post',
            url : Z.url('/backend/setting/update_by_key',true),
            data: {key: 'home_top_news_type',value : 2}
        });
    });
});